package com.glf.tool.utils;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;

import java.io.File;
import java.util.List;

public class EasyExcelUtil {
    public static <T> List<T> importExcel(File file, Class<T> pojoClass) {
        ImportParams params = new ImportParams();
        params.setTitleRows(0);
        params.setHeadRows(1);
        params.setKeyIndex(1);
        return importExcelExcep(file, pojoClass, params);
    }

    public static <T> List<T> importExcelExcep(File file, Class<T> pojoClass, ImportParams params) {
        List<T> list = null;
        try {
            //ExcelImportUtil  是包   cn.afterturn.easypoi.excel;
            list = ExcelImportUtil.importExcel(file, pojoClass, params);
//            list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
        } catch (Exception e) {
            System.out.println("导入失败");
            throw new RuntimeException("导入失败");
        }
        return list;
    }
}